#! /bin/sh
set timeout 30
set path [lindex $argv 0]
set random [lindex $argv 1]
spawn openssl req -newkey rsa:2048 -out $path -nodes
expect -r "Country Name.*:$"
send "US\r"
expect -r "State or Province Name.*:$"
send "\r"
expect -r "Locality Name.*:$"
send "\r"
expect -r "Organization Name.*:$"
send "Apple\r"
expect -r "Organizational Unit Name.*:$"
send "\r"
expect -r "Common Name.*:$"
send "\r"
expect -r "Email Address.*:$"
send "${random}\r"
expect -r "A challenge password.*:$"
send "Apple\r"
expect eof